from common.utils.rights import permission_required, view_logging_required
from common.utils.file_read import file_read
from . import index_bp
from flask import render_template,request
from flask_wtf.form import CombinedMultiDict
from models.form import UploadForm
import cv2


# 用户增加
@index_bp.get('/gray_pro')
@index_bp.post('/gray_pro')
@view_logging_required
@permission_required("gray:pro")
def gray_pro():
    if request.method == "GET":
        return render_template('admin/cv/gray.html')
    else:
        form = UploadForm(CombinedMultiDict([request.form, request.files]))
        f = request.files['file']
        file_url = file_read(f)
        # 图像灰度化
        pic = cv2.imread(file_url)
        image = cv2.cvtColor(pic, cv2.COLOR_BGR2RGB)
        image = cv2.imread(file_url, cv2.IMREAD_GRAYSCALE)
        res_pic = "static/download/gama.jpg"
        cv2.imwrite(res_pic,image)
        return render_template('admin/cv/gray.html',pic=file_url,res_pic=res_pic)

